import string

class HomoDecipher:
    def _init_(self):
        self.parentkey = ''
        
        
    def getkey(self, parentkey,message):
        self.parentkey = parentkey       
        
        self.message = message
        self.values = {}
        templist = list()
        for i in range (0,11):
            templist.append(parentkey[i])
        self.values['a'] = templist
        templist1 = list()
        for ii in range (11,13):
            templist1.append(parentkey[ii])
        self.values['b'] = templist1
        templist2 = list()
        for ii in range (13,16):
            templist2.append(parentkey[ii])
        self.values['c'] = templist2
        templist3 = list()
        for ii in range (16,18):
            templist3.append(parentkey[ii])
        self.values['d'] = templist3
        templist4 = list()
        for ii in range (18,31):
            templist4.append(parentkey[ii])
        self.values['e'] = templist4
        templist5 = list()
        for ii in range (31,33):
            templist5.append(parentkey[ii])
        self.values['f'] = templist5
        templist6 = list()
        for ii in range (33,35):
            templist6.append(parentkey[ii])
        self.values['g'] = templist6
        templist7 = list()
        for ii in range (35,37):
            templist7.append(parentkey[ii])
        self.values['h'] = templist7
        templist8 = list()
        for ii in range (37,49):
            templist8.append(parentkey[ii])
        self.values['i'] = templist8
        templist9 = list()
        for ii in range (49,50):
            templist9.append(parentkey[ii])
        self.values['j'] = templist9
        templist10 = list()
        for ii in range (50,52):
            templist10.append(parentkey[ii])
        self.values['k'] = templist10
        templist11 = list()
        for ii in range (52,56):
            templist11.append(parentkey[ii])
        self.values['l'] = templist11
        templist12 = list()
        for ii in range (56,59):
            templist12.append(parentkey[ii])
        self.values['m'] = templist12
        templist13 = list()
        for ii in range (59,66):
            templist13.append(parentkey[ii])
        self.values['n'] = templist13
        templist14 = list()
        for ii in range (66,75):
            templist14.append(parentkey[ii])
        self.values['o'] = templist14
        templist15 = list()
        for ii in range (75,77):
            templist15.append(parentkey[ii])
        self.values['p'] = templist15
        templist16 = list()
        for ii in range (77,78):
            templist16.append(parentkey[ii])
        self.values['q'] = templist16
        templist17 = list()
        for ii in range (78,84):
            templist17.append(parentkey[ii])
        self.values['r'] = templist17
        templist18 = list()
        for ii in range (84,89):
            templist18.append(parentkey[ii])
        self.values['s'] = templist18
        templist19 = list()
        for ii in range (89,97):
            templist19.append(parentkey[ii])
        self.values['t'] = templist19
        templist20 = list()
        for ii in range (97,100):
            templist20.append(parentkey[ii])
        self.values['u'] = templist20
        templist21 = list()
        for ii in range (100,101):
            templist21.append(parentkey[ii])
        self.values['v'] = templist21
        templist22 = list()
        for ii in range (101,103):
            templist22.append(parentkey[ii])
        self.values['w'] = templist22
        templist23 = list()
        for ii in range (103,104):
            templist23.append(parentkey[ii])
        self.values['x'] = templist23
        templist24 = list()
        for ii in range (104,106):
            templist24.append(parentkey[ii])
        self.values['y'] = templist24
        templist25 = list()
        for ii in range (106,107):
            templist25.append(parentkey[ii])
        self.values['z'] = templist25
        templist26 = list()
        for ii in range (107,110):
            templist26.append(parentkey[ii])
        self.values['.'] = templist26
        templist27 = list()
        for ii in range (110,113):
            templist27.append(parentkey[ii])
        self.values[','] = templist27
        templist28 = list()
        for ii in range (113,115):
            templist28.append(parentkey[ii])
        self.values['?'] = templist28
        templist29 = list()
        for ii in range (115,116):
            templist29.append(parentkey[ii])
        self.values['!'] = templist29
        templist30 = list()
        for ii in range (116,119):
            templist30.append(parentkey[ii])
        self.values[' '] = templist30       
        for ii in range (119,121):
            templist.append(parentkey[ii])
        self.values['a'] = templist
        ##print self.values['a']
        for ii in range (121,123):
            templist24.append(parentkey[ii])
        self.values['y'] = templist24
        for ii in range (123,125):
            templist4.append(parentkey[ii])
        self.values['e'] = templist4
        for ii in range (125,127):
            templist15.append(parentkey[ii])
        self.values['p'] = templist15
        for ii in range (127,130):
            templist20.append(parentkey[ii])
        self.values['u'] = templist20
        
       
        
        ##print self.values
        string1 = self.decipher(self.message)
        return string1
                  
    def decipher(self,message):
        string = ''
        position = 0
        ##print self.values.items()
        while position<= len(message)-2:            
            items = self.values.items()
            
            substring = message[position:position+2]
            if(substring.isdigit() == False):
                substring = message[position:position+1]
                position+=1
            else:                
                position+=2    
            for item in items:
                ##print item
                word = item[0]
                cipher = item[1]   
               ## print cipher            
                if substring in cipher:
                   
                    string += word  

        return string
        